﻿/*====================================================================================
* Copyright (c) 2015-2026成都长益西联软件有限公司,All Rights Reserved.
*=====================================================================================
* 文件名称：ChkWrdTool
* 功能描述：ChkWrdTool 
* 创 建 者：HFL
* 创建时间：2016-8-26 10:48:16
* 修 改 者：HFL
* 修改时间：2016-8-26 10:48:16
*===================================================================================*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace WPay.Infrastructure.Unity
{
    /// <summary>
    /// ChkWrd校验字工具类
    /// 提供功能【1.验证ChkWrd校验字是否正确
    /// 2.计算ChkWrd校验字】
    /// </summary>
    public class ChkWrdTool
    {
        /// <summary>
        /// 验证ChkWrd校验字是否正确
        /// </summary>
        /// <param name="chkWrd">原始校验字</param>
        /// <param name="param">计算校验字的参数</param>
        /// <returns>返回是否正确[true:正确;false:失败]</returns>
        public static bool ChkWrd(string chkWrd, params object[] param)
        {
            //若校验字为空，拒绝访问
            if (string.IsNullOrEmpty(chkWrd))
                return false;
            //组织参数校验字串
            string chkWrdStr = GetChkWrd(param);
            //验证校验字是否正确
            if (chkWrd.ToUpper().Equals(chkWrdStr.ToUpper()))
            {
                return true;
            }
            return false;
        }
        /// <summary>
        /// 计算ChkWrd校验字
        /// </summary>
        /// <param name="param">计算校验字的参数</param>
        /// <returns>返回校验字</returns>
        public static string GetChkWrd(params object[] param) {
            //组织参数校验字串
            string chkWrdStr = "";
            if (param != null && param.Length > 0)
            {
                for (int i = 0; i < param.Length; i++)
                {
                    if (param[i] == null || string.IsNullOrEmpty(param[i].ToString()))
                        continue;
                    chkWrdStr += param[i].ToString();
                }
            }
            //计算校验字
            chkWrdStr = DESEncrypt.EncryptByMD5(chkWrdStr, true);
            return chkWrdStr;
        }
    }
}